﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta charset="utf-8" />
    <title>发送邮件</title>
    <!--Jquery-->
    <script src="../../WF/Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="../../WF/Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>

    <!--bootstrap-->
    <link href="../../WF/Scripts/bootstrap/css/bootstrap.css" rel="Stylesheet" />
    <link href="../../WF/Scripts/bootstrap/css/font-awesome.css" rel="Stylesheet" />
    <link  href="../../WF/Scripts/bootstrap/css/css.css" type="text/css"rel="stylesheet"  media="all" />
    <script src="../../WF/Scripts/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="../../WF/Scripts/bootstrap/js/jquery.cokie.min.js" type="text/javascript"></script>
    <script src="../../WF/Scripts/bootstrap/BootstrapUIDialog.js" type="text/javascript"></script>

    <!-- 引用基础js库. -->
    <script src="../../WF/Scripts/QueryString.js" type="text/javascript" ></script>
    <script src="../../WF/Scripts/QueryString2016.js" type="text/javascript" ></script>
    <script src="../../WF/Scripts/config.js?ver=1" type="text/javascript"></script>
    <script src="../../WF/Comm/Gener.js?ver=1" type="text/javascript"></script>
    <script src="../../WF/Comm/JScript.js?ver=1" type="text/javascript"></script>

     <!--KindeEditor-->
    <link  href="./kindeditor/themes/default/default.css" rel="stylesheet"/>
    <link  href="./kindeditor/plugins/code/prettify.css" rel="stylesheet"/>
    <script src="./kindeditor/kindeditor.js" type="text/javascript" charset="utf-8" ></script>
    <script src="./kindeditor/lang/zh_CN.js" type="text/javascript" charset="utf-8" ></script>
    <script src="./kindeditor/plugins/code/prettify.js" type="text/javascript" charset="utf-8"></script>


    <!--邮件引入的基本信息-->
   <link href="SendMsg.css" rel="Stylesheet" />
    <link href="layer/layer.css" rel="Stylesheet" />
    <script src="layer/layer.js" type="text/javascript"></script>
    <script src="SendMsgTag.js" type="text/javascript"></script>
    <script src="SendMsg.js" type="text/javascript"></script>
    <script src="resize.js" type="text/javascript"></script>
    
    <script src="msgComm.js" type="text/javascript"></script>

    <style type="text/css">
     .nui-iput{
         width: 100%; 
        border-width: 0;
        background-color: transparent; 
        box-shadow: none;
        cursor: text;
        position: relative;
        padding: 9px 0 6px;
        zoom: 1;
    }
    </style>
    <script type="text/javascript">

        var receiverDatas = []; //接受者人员集合

        var ccDatas = []; //抄送者人员集合
        var editor;

        $(function () {
            initBar();

            $("#recevierDiv").sendMsgTag({
                "fit": true,
                "onUnselect": function (record) {

                }
            });

            $("#CCerDiv").sendMsgTag({
                "fit": true,
                "onUnselect": function (record) {

                }
            });

            if (plant == "CCFlow") {
                editor = KindEditor.create('#TB_Docs', {
                    cssPath: './kindeditor/plugins/code/prettify.css',
                    uploadJson: './kindeditor/asp.net/upload_json.ashx',
                    fileManagerJson: './ctrl/kindeditor/asp.net/file_manager_json.ashx',
                    allowFileManager: true
                });
                //editor.sync();
                prettyPrint();

            } else {
                KindEditor.ready(function (K) {
                    editor = KindEditor.create('#TB_Docs', {
                        cssPath: './ctrl/kindeditor/plugins/code/prettify.css',
                        uploadJson: './ctrl/kindeditor/jsp/upload_json.jsp',
                        fileManagerJson: './ctrl/kindeditor/jsp/file_manager_json.jsp',
                        allowFileManager: true
                    });
                    //editor.sync();
                    prettyPrint();
                });
            }

            //获取URL上的参数
            var MyPK = GetQueryString("PKVal");
            var ResourceType = GetQueryString("ResourceType");
            if (MyPK != null && MyPK != "" && MyPK != undefined) {
                var en = new Entity("BP.OA.Message.InBox", MyPK);

                if (ResourceType == 0)
                    $("#recevierDiv").sendMsgTag("loadData", [{ "No": en.Sender, "Name": en.SenderName}]);

                if (ResourceType == 0)
                    $("#TB_Title").val("Re:" + en.Title);
                if (ResourceType == 1)
                    $("#TB_Title").val("Fw:" + en.Title);

                var sendTime = en.SendTime;

                var ttDate = sendTime.replace(/(\d{4}).(\d{1,2}).(\d{1,2}).+/mg, '$1年$2月$3日') + sendTime.substring(10);

                var docs = en.Docs;
                docs = docs.replace(/~/g, "");

                //给内容赋值
                editor.html("<br/><br/>------原始邮件------<div style='background-color:#eeeeee;padding:2px 2px 2px 2px;'><b>发件人</b>: " + en.SenderName + "</b><b>发送时间</b>:" + ttDate + "(" + getWeekDay(sendTime) + ")<br/><b>收件人</b>:" + new WebUser().Name + " <br/><b>主题</b>: " + en.Title + "</div><br/>" + docs + "");

            }

        });
       

        //保存草稿箱
        function Save() {
            var en = new Entity("BP.OA.Message.SendBox");
            en.CopyForm();
            en.IsSend = 0; //未发送进草稿箱
            //获取接收者
            var receviers = $("#recevierDiv").find(".message_div-container div");
            var receiver = "";
            receviers.each(function () {
                receiver += $(this).data()["No"] + ",";
            });
            //获取抄送者
            var CCers = "";
            var CCerDivs = $("#CCerDiv").find(".message_div-container div");
            CCerDivs.each(function () {
                CCers += $(this).data()["No"] + ",";
            });
          
            en.Receiver = receiver;
            en.CCers = CCers;
            var docs = editor.html();
            docs = docs.replace(/\"/g,"\'");
            en.Docs = docs;
            en.Sender = new WebUser().No;
            var data = en.Save();
            if (data == 1)
                alert("保存成功");
            else
                alert("保存失败");
        }

        //发送邮件
        function Send() {
            //获取到的收件人
           var receviers = $("#recevierDiv").find(".message_div-container div");
           if (receviers.length == 0) {
                alert('请选择收件人');
                return;
            }
            var sendEn = new Entity("BP.OA.Message.SendBox");
            sendEn.CopyForm();
            sendEn.IsSend = 1; //未发送进草稿箱
            var docs = editor.html();
            docs = docs.replace(/\"/g, "\'");
            sendEn.Docs = docs;

            var receiver = "";
            receviers.each(function() {
                receiver += $(this).data()["No"] + ",";
            });

            //获取抄送人
            var CCers = "";
            var CCerDivs = $("#CCerDiv").find(".message_div-container div");
            CCerDivs.each(function () {
                CCers += $(this).data()["No"] + ",";
            });
          

            sendEn.Receiver = receiver;
            sendEn.CCers = CCers;
            sendEn.Sender = new WebUser().No;
            sendEn = sendEn.Insert();
            if (sendEn == 0) {
                alert("发送失败");
                return;
            }
            //获取接受者信息
            var receiver = "";
            receviers.each(function () {
                var en = new Entity("BP.OA.Message.InBox");
                en.Sender = new WebUser().No;
                en.SenderName = new WebUser().Name;
                en.Receiver = sendEn.Receiver;
                en.CCers = sendEn.CCers;
                en.SendTime = sendEn.SendTime;
                en.Title = sendEn.Title;
                en.Docs = sendEn.Docs;
                en.MyPK = sendEn.MyPK + "_" + $(this).data()["No"];
                en.UserNo = $(this).data()["No"];
                en.RefMsg = sendEn.MyPK;
                en.InBoxState = 0;
                en.MsgType = 0;
                en.Save();
            });

            //获取抄送者信息
            if (CCerDivs.length == 0) {
                alert("发送成功");
                window.location.href = 'InBox.htm';
                return;
            }
            CCerDivs.each(function () {
                var en = new Entity("BP.OA.Message.InBox");
                en.Sender = new WebUser().No;
                en.SenderName = new WebUser().Name;
                en.Receiver = sendEn.Receiver;
                en.CCers = sendEn.CCers;
                en.SendTime = sendEn.SendTime;
                en.Title = sendEn.Title;
                en.Docs = sendEn.Docs;

                en.MyPK = sendEn.MyPK + "_" + $(this).data()["No"];
                en.UserNo = $(this).data()["No"];
                en.RefMsg = sendEn.MyPK;
                en.InBoxState = 0;
                en.MsgType = 1;
                en.Save();
            });

            alert("发送成功");
        }

        //清空页面内容
        function Clear() {
            
            var container = $("#recevierDiv").find(".message_div-container");
            container.children("div").remove();

            var container = $("#CCerDiv").find(".message_div-container");
            container.children("div").remove();
            $("#TB_Receiver").val("");
            $("#TB_CCer").val("");
            $("#TB_Title").val("");
            editor.html("");
        }


    </script>
     <style type="text/css">
        .div-group-addon{
            padding: 8px 16px;
            font-size: 14px;
            font-weight: normal;
            line-height: 1;
            color: #555;
            text-align: center;
            background-color: #eee;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .div-group-addon:last-child
        {
            border-left: 0;
            border-top-left-radius: 0px;
            border-bottom-left-radius: 0px;
        }
    </style>
</head>
<body>
<div id="alls" style="">
    <div  id="toolBar" style="margin-left:30px"><br /></div>
    <div  style="margin:15px 0px 15px 60px;text-align:left">
        <button type="button" class="btn btn-success"  data-dismiss="modal" onclick="Send()"><span class="glyphicon glyphicon-envelope" aria-hidden="true"></span>发送</button>
        <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="Save()"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>存草稿</button>
        <button type="button" class="btn btn-default" data-dismiss="modal" onclick="Clear()"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>取消</button>
      </div>

    <div  style="margin-left:30px;margin-right:3px">
         <div class="form-group" >
            <label class="col-sm-1 control-label" style="width:80px" for="TB_Receiver">接收人:</label>    
            <div class="col-sm-11">
                <div id="recevierDiv" class="noime div_txt" style="float:left;cursor: text;width:96%; min-height: 34px;color: #555; background-color: #fff; background-image: none;border: 1px solid #ccc; border-top-left-radius: 4px;border-bottom-left-radius: 4px; " >
	                <div style="position: absolute; color: rgb(160, 160, 160); padding-top: 1px; display: none;"></div>
                    <div class="message_div-container" style="padding-top:4px"></div>
	                <div class="addr_text" style="float: left; border: none; overflow: hidden; width: 120px;">
		                <input id="TB_Receiver" type="input" class="js_input" style="border:none;outline:none;-webkit-appearance:none;width:100%;" accesskey="t" tabindex="1" autocomplete="off"/>
		                <div style="width: 1px; height: 1px; overflow: auto; white-space: nowrap; border: none; margin: 0px; padding: 0px; font-family: Tahoma; font-size: 12px; font-weight: 400; line-height: normal; word-spacing: 0px;">WW</div>
	                </div>
	                <div style="clear:both;border:none;margin:0;padding:0;" unselectable="on"><input type="text" style="position:absolute;border:none;padding:0;width:10px;left:-9999px;top:-9999px;"tabindex="-1"></div>
                </div>
                 <div style="float:left; border-radius: 4px;width:4%;margin-top:9px" >
                    <span class="div-group-addon" style="width: 100%;height:34px; white-space: nowrap;vertical-align: middle;">
                        <a href="javaScript:void(0)" onclick="SelectEmp(0,'recevierDiv')"><span class="glyphicon glyphicon-plus"></span></a>
                    </span>
                </div>
            </div>
        </div>
        <br />
        <div class="form-group" >
            <label class="col-sm-1 control-label" style="width:80px">抄送人:</label>    
            <div class="col-sm-11">
                <div id="CCerDiv" class="noime div_txt" style="float:left;cursor: text;width:96%; min-height: 34px;color: #555; background-color: #fff; background-image: none;border: 1px solid #ccc;    border-top-left-radius: 4px;border-bottom-left-radius: 4px; " >
	                <div style="position: absolute; color: rgb(160, 160, 160); padding-top: 1px; display: none;"></div>
                    <div class="message_div-container" style="padding-top:4px"></div>
	                <div class="addr_text" style="float: left; border: none; overflow: hidden; width: 120px;">
		                <input id="TB_CCer" type="input" class="js_input" style="border:none;outline:none;-webkit-appearance:none;width:100%;" accesskey="t" tabindex="1" autocomplete="off"/>
		                <div style="width: 1px; height: 1px; overflow: auto; white-space: nowrap; border: none; margin: 0px; padding: 0px; font-family: Tahoma; font-size: 12px; font-weight: 400; line-height: normal; word-spacing: 0px;">WW</div>
	                </div>
	                <div style="clear:both;border:none;margin:0;padding:0;" unselectable="on"><input type="text" style="position:absolute;border:none;padding:0;width:10px;left:-9999px;top:-9999px;"tabindex="-1"></div>
                </div>
                <div style="float:left; border-radius: 4px;width:4%;margin-top:9px" >
                   <span class="div-group-addon" style="width: 100%;height:34px; white-space: nowrap;vertical-align: middle;">
                       <a href="javaScript:void(0)" onclick="SelectEmp(0,'CCerDiv')"><span class="glyphicon glyphicon-plus"></span></a>
                   </span>
                </div>
            </div>
        </div>
         <br />
        <div class="form-group" >
            <label class="col-sm-1 control-label" style="width:80px" for="TB_Title">标题:</label>
            <div class="col-sm-11">
                 <input type="text" id="TB_Title" name="TB_Title" class="form-control"/>
            </div>
        </div>
         <br />
          <div class="form-group">
            <label class="col-sm-1 control-label" style="width:80px" for="TB_Docs">内容</label>
            <div class="col-sm-11">
                <div style='white-space:normal;'>
                    <textarea rows="" cols="" id="TB_Docs" name="TB_Docs" style='text-align:left;font-size:12px;width:100%;height:260px'></textarea>
                </div>
            </div>           
          </div>
        </div>
        <div class="footer"  style="margin:15px 0px 0px 60px;text-align:left">
             <button type="button" class="btn btn-success" id="send" data-dismiss="modal" onclick="Send()"><span class="glyphicon glyphicon-envelope" aria-hidden="true"></span>发送</button>
             <button type="button" id="btn_submit" class="btn btn-primary" data-dismiss="modal" onclick="Save()"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>存草稿</button>
             <button type="button" class="btn btn-default" id="btn_close" data-dismiss="modal" onclick="Clear()"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>取消</button>
          </div>
     </div> 
</body>
</html>
